<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page import="java.sql.Connection, 
java.sql.DriverManager,
java.sql.Statement,
java.sql.ResultSet" %>
<%@ include file="admin\definisi.jsp" %>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Sistem Informasi Pengelolaan Pendingin Ruangan</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link rel="stylesheet" href="style.css" type="text/css" media="screen" />
    </head>
    <body>
        <!-- Wrapper Starts -->
        <div id="wrapper">
            <!-- Header Starts -->
            <div id="header">
                <!-- Logo Starts -->
                <div id="logo">
                    <h1> Biro Sarana <font color="#666666"> Prasarana </font> </h1>
                    <h2> Sistem Informasi Berbasis Web&bull;<br> Pengelolaan Pendingin Ruangan&bull;<br> Universitas Sanata Dharma Yogayakarta</h2>
                </div>
                
                <!-- Logo Ends -->
            </div>
            <!-- Header Ends -->
            <!-- Menu Starts -->
            <div id="menu">
                <!-- Menu Items Starts -->
                <ul>
                    <li><a href="halPengunjung.jsp" class="current"><span>home</span></a></li>
                    <li><a href="halAduanKerusakan.jsp?kampus=all&unit=all&lantai=all&ruang=all&merek=all&jenis=all"><span>aduan kerusakan</span></a></li>
                </ul>
                <!-- Menu Items Ends -->
            </div>
            <!-- Menu Ends -->
            <!-- Container Starts -->
            <div id="container" class="clearfix">
                <!-- Mainarea Starts -->
                <div id="mainarea">
                    <h2>Form Pengaduan Kerusakan</h2>
                       <%
                boolean ada_kesalahan = false;
                
                try {
                    Class.forName("com.mysql.jdbc.Driver");
                } catch (Exception ex) {
                    out.println("Kesalahan: " + ex);
                    ada_kesalahan = true;
                }
                
                if (!ada_kesalahan) {
                    // Bentuk koneksi
                    Connection koneksi = null;
                    try {
                        koneksi = DriverManager.getConnection(
                                NAMA_DB,
                                NAMA_USER, PASSWORD);
                    } catch (Exception ex) {
                        out.println("Kesalahan: " + ex);
                        ada_kesalahan = true;
                    }
                    
                    if (!ada_kesalahan) {
                        ResultSet hasilQuery = null;
                        ResultSet getIDAC=null;
                        ResultSet RuangEdit=null;
                        ResultSet getNamaUnit=null;
                        ResultSet getNamaUnitUrut=null;
                        ResultSet getNamaKampus=null;
                        ResultSet getNamaKampusUrut=null;
                        ResultSet getNamaLantai=null;
                        ResultSet getNamaLantaiUrut=null;
                        ResultSet getNamaRuang=null;
                        ResultSet getNamaRuangUrut=null;
                        ResultSet getMerekAC=null;
                        ResultSet getJenisAC=null;
                        ResultSet getMerekACUrut=null;
                        ResultSet getJenisACUrut=null;
                        String IDAC=null;
                        try {
                            Statement stm = koneksi.createStatement();
                            Statement stm2 = koneksi.createStatement();
                            Statement stm3 = koneksi.createStatement();
                            Statement stm4 = koneksi.createStatement();
                            Statement stm5 = koneksi.createStatement();
                            Statement stm6 = koneksi.createStatement();
                            Statement stm7 = koneksi.createStatement();
                             Statement stm8 = koneksi.createStatement();
                            Statement stm9 = koneksi.createStatement();
                            Statement stm10 = koneksi.createStatement();
                            Statement stm11 = koneksi.createStatement();
                            Statement stm12 = koneksi.createStatement();
                            Statement stm13 = koneksi.createStatement();
                            Statement stm14 = koneksi.createStatement();
                            Statement stm15 = koneksi.createStatement();
                            hasilQuery = stm.executeQuery( "SELECT merek.merek,jenis.jenis,ac.id_AC,ac.id_merek,ac.id_jenis,ac.model,ac.no_seri,ac.jumlah_PK,ac.tahun_beli,ruang.id_ruang,ruang.nama_ruang,unit.id_unit,kampus.id_kampus,lantai.id_lantai,lantai.nama_lantai,unit.nama_unit,kampus.nama_kampus FROM lantai,unit,kampus,ruang,ac,merek,jenis WHERE unit.id_unit=lantai.id_unit AND kampus.id_kampus=unit.id_kampus AND ruang.id_lantai=lantai.id_lantai AND ruang.id_ruang=ac.id_ruang AND merek.id_merek=ac.id_merek AND jenis.id_jenis=ac.id_jenis ORDER BY id_AC");
                            getIDAC=stm2.executeQuery("select max(substring(id_ac,2)) from ac");
                            RuangEdit=stm3.executeQuery("SELECT ruang.nama_ruang,ruang.id_ruang,lantai.id_lantai,lantai.nama_lantai,unit.nama_unit,kampus.nama_kampus,unit.id_unit,kampus.id_kampus FROM lantai,unit,kampus,ruang WHERE unit.id_unit=lantai.id_unit AND kampus.id_kampus=unit.id_kampus AND lantai.id_lantai=ruang.id_lantai AND ruang.id_ruang='"+request.getParameter("kode")+"' ORDER BY id_ruang");
                            getNamaKampus=stm4.executeQuery("SELECT nama_kampus,id_kampus from kampus ORDER BY id_kampus");
                            getNamaUnit=stm5.executeQuery("SELECT nama_unit,id_kampus,id_unit from unit WHERE id_kampus='"+request.getParameter("kampus")+"'");
                            getNamaKampusUrut=stm6.executeQuery("SELECT nama_kampus,id_kampus from kampus ORDER BY id_kampus='"+request.getParameter("kampus")+"' DESC");
                            getNamaUnitUrut=stm7.executeQuery("SELECT nama_unit,id_kampus,id_unit from unit WHERE id_kampus='"+request.getParameter("kampus")+"' ORDER BY id_unit='"+request.getParameter("unit")+"' DESC");
                            getNamaLantai=stm8.executeQuery("SELECT nama_lantai,id_unit,id_lantai from lantai WHERE id_unit='"+request.getParameter("unit")+"'");
                            getNamaLantaiUrut=stm9.executeQuery("SELECT nama_lantai,id_lantai,id_unit from lantai WHERE id_unit='"+request.getParameter("unit")+"' ORDER BY id_lantai='"+request.getParameter("lantai")+"' DESC");
                            getNamaRuang=stm10.executeQuery("SELECT nama_ruang,id_lantai,id_ruang from ruang WHERE id_lantai='"+request.getParameter("lantai")+"'");
                            getNamaRuangUrut=stm11.executeQuery("SELECT nama_ruang,id_ruang,id_lantai from ruang WHERE id_lantai='"+request.getParameter("lantai")+"' ORDER BY id_ruang='"+request.getParameter("ruang")+"' DESC");
                            getMerekAC=stm12.executeQuery("SELECT merek.id_merek,merek.merek from merek ORDER BY merek.id_merek DESC");
                            getJenisAC=stm13.executeQuery("SELECT jenis.id_jenis,jenis.jenis from jenis ORDER BY jenis.id_jenis DESC");
                            getMerekACUrut=stm14.executeQuery("SELECT merek.id_merek,merek.merek from merek ORDER BY merek.id_merek='"+request.getParameter("merek")+"' DESC");
                            getJenisACUrut=stm15.executeQuery("SELECT jenis.id_jenis,jenis.jenis from jenis ORDER BY jenis.id_jenis='"+request.getParameter("jenis")+"' DESC");
                        } catch (Exception ex) {
                            out.println("Kesalahan: " + ex);
                            ada_kesalahan = true;
                        }
                        
                        if (!ada_kesalahan) {
                            try {
                                while(getIDAC.next()){
                                    IDAC="A"+(getIDAC.getInt(1)+1);
                                }
                                %>
                                <%
                    if (request.getParameter("msg") != null)
                        out.println( "<center><p style='color:#FF0000'>"+request.getParameter("msg") + "<BR>\n</p></center>");
                    %>
                <form action="LihatLokasiAC.jsp?id_kampus=<%out.print(request.getParameter("kampus"));%>&id_unit=<%out.print(request.getParameter("unit"));%>&id_lantai=<%out.print(request.getParameter("lantai"));%>&id_ruang=<%out.print(request.getParameter("ruang"));%>" method="post">
                    <table>
                        
                        <tr>
                            <td>
                                Lokasi Kampus
                            </td>
                            <td>
                                <select name="nama_kampus">
                                    <%
                                    if(request.getParameter("kampus").equals("all")){
                                    while(getNamaKampus.next()){%>
                                    <option onclick="location.href='halAduanKerusakan.jsp?proses=tambah&kampus=<%out.print(getNamaKampus.getString("id_kampus"));%>&unit=all&lantai=all&ruang=all&merek=all&jenis=all'"><%out.print(getNamaKampus.getString("nama_kampus"));%></option>
                                <%
                                    }
                                    }
                                    else{
                                    while(getNamaKampusUrut.next()){%>
                                     <option onclick="location.href='halAduanKerusakan.jsp?proses=tambah&kampus=<%out.print(getNamaKampusUrut.getString("id_kampus"));%>&unit=all&lantai=all&ruang=all&merek=all&jenis=all'"><%out.print(getNamaKampusUrut.getString("nama_kampus"));%></option>
                                <%}
                                    }
                                %>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Lokasi Unit
                            </td>
                            <td>
                                <select name="nama_unit">
                                    <%
                                    if(request.getParameter("unit").equals("all")){
                                    while(getNamaUnit.next()){%>
                                    <option onclick="location.href='halAduanKerusakan.jsp?proses=tambah&kampus=<%out.print(getNamaUnit.getString("id_kampus"));%>&unit=<%out.print(getNamaUnit.getString("id_unit"));%>&lantai=all&ruang=all&merek=all&jenis=all'"><%out.print(getNamaUnit.getString("nama_unit"));%></option>
                               <% }
                                    }
                                    else{
                                    while(getNamaUnitUrut.next()){%>
                                    <option onclick="location.href='halAduanKerusakan.jsp?proses=tambah&kampus=<%out.print(getNamaUnitUrut.getString("id_kampus"));%>&unit=<%out.print(getNamaUnitUrut.getString("id_unit"));%>&lantai=all&ruang=all&merek=all&jenis=all'"><%out.print(getNamaUnitUrut.getString("nama_unit"));%></option>
                                <% }
                                    }
                                %>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Lokasi Lantai
                            </td>
                            <td>
                                <select name="nama_lantai">
                                    <%
                                    if(request.getParameter("lantai").equals("all")){
                                    while(getNamaLantai.next()){%>
                                    <option onclick="location.href='halAduanKerusakan.jsp?proses=tambah&kampus=<%out.print(request.getParameter("kampus"));%>&unit=<%out.print(getNamaLantai.getString("id_unit"));%>&lantai=<%out.print(getNamaLantai.getString("id_lantai"));%>&ruang=all&merek=all&jenis=all'"><%out.print(getNamaLantai.getString("nama_lantai"));%></option>
                               <% }
                                    }
                                    else{
                                    while(getNamaLantaiUrut.next()){%>
                                  <option onclick="location.href='halAduanKerusakan.jsp?proses=tambah&kampus=<%out.print(request.getParameter("kampus"));%>&unit=<%out.print(getNamaLantaiUrut.getString("id_unit"));%>&lantai=<%out.print(getNamaLantaiUrut.getString("id_lantai"));%>&ruang=all&merek=all&jenis=all'"><%out.print(getNamaLantaiUrut.getString("nama_lantai"));%></option>
                                <% }
                                    }
                                %>
                                </select>
                            </td>
                        </tr>
                             <tr>
                            <td>
                                Lokasi Ruang
                            </td>
                            <td>
                                <select name="nama_ruang">
                                    <%
                                    if(request.getParameter("ruang").equals("all")){
                                    while(getNamaRuang.next()){%>
                                    <option onclick="location.href='halAduanKerusakan.jsp?proses=tambah&kampus=<%out.print(request.getParameter("kampus"));%>&unit=<%out.print(request.getParameter("unit"));%>&lantai=<%out.print(getNamaRuang.getString("id_lantai"));%>&ruang=<%out.print(getNamaRuang.getString("id_ruang"));%>&merek=all&jenis=all'"><%out.print(getNamaRuang.getString("nama_ruang"));%></option>
                               <% }
                                    }
                                    else{
                                    while(getNamaRuangUrut.next()){%>
                                  <option onclick="location.href='halAduanKerusakan.jsp?proses=tambah&kampus=<%out.print(request.getParameter("kampus"));%>&unit=<%out.print(request.getParameter("unit"));%>&lantai=<%out.print(getNamaRuangUrut.getString("id_lantai"));%>&ruang=<%out.print(getNamaRuangUrut.getString("id_ruang"));%>&merek=all&jenis=all'"><%out.print(getNamaRuangUrut.getString("nama_ruang"));%></option>
                                <% }
                                    }
                                %>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <input type="submit" value="LANJUT>>"/>
                            </td>
                            <td>
                                <input type="reset" value="RESET"/>
                            </td>
                        </tr>
                    </table>
                    
                </form>
                <% 
                                }catch (Exception ex) {
                                out.println("Kesalahan: " + ex);
                                ada_kesalahan = true;
                            }
                            
                        }
                    }
                }
                %>
                    </div>
                <!-- Mainarea Ends -->
                <!-- Sidearea Starts -->
                <div id="sidearea">
                   
                </div>
                <!-- Sidearea Ends -->
            </div>
            <!-- Container Ends -->
            <!-- Footer Starts -->
            <div id="footer">
                <p class="floatleft">Fransiscus Anggit || Tugas Akhir || 065314022</p>
            </div>
            <!-- Footer Ends -->
        </div>
        <!-- Wrapper Ends -->
    </body>
</html>
